package com.ymatou.iapi.prodstock.testcase;

import com.ymatou.iapi.prodstock.parameter.AuditProductActivityStockBean;
import com.ymatou.iapi.prodstock.parameter.UpdateProductActivityStockActionBean;
import com.ymatou.iapi.prodstock.service.UpdateProductActivityStockActionCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymttest.business.service.ProdStockCallService;
import com.ymttest.database.model.YmtProductActivityStock;
import com.ymttest.database.sqlwapper.YmtProductActivityStockWapper;
import com.ymttest.utils.EnvSetup;
import org.junit.*;
import org.junit.experimental.categories.Category;
/**
*更新活动更新活动商品状态
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_UpdateProductActivityStockAction{
	private static UpdateProductActivityStockActionBean updateproductactivitystockactionBean;
	private static UpdateProductActivityStockActionCall updateproductactivitystockactionCall;
    private static int sellerId = Integer.parseInt(EnvSetup.getData("autotest_seller1"));
    @BeforeClass
	public static void setUp() {
		Logger.createResultFile("更新活动更新活动商品状态");
	}

	@Before
	public void caseUp() {
		updateproductactivitystockactionBean=new UpdateProductActivityStockActionBean();
		updateproductactivitystockactionCall=new UpdateProductActivityStockActionCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(updateproductactivitystockactionCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_UpdateProductActivityStockAction_01() {
		Logger.start(true,"更新活动更新活动商品状态,预售活动");
		try {
            AuditProductActivityStockBean activityStockBean = ProdStockCallService.initAuditProductActivityStockBean(sellerId);
            activityStockBean.setActivityType(2);
            activityStockBean.getFBXCatalogLockList().get(0).setEarnest(10);
            activityStockBean.getFBXCatalogLockList().get(0).setEarnestDedution(15);
            activityStockBean.getFBXCatalogLockList().get(0).setAction(1);

			activityStockBean.getFBXCatalogLockList().get(1).setEarnest(20);
			activityStockBean.getFBXCatalogLockList().get(1).setEarnestDedution(10);
			activityStockBean.getFBXCatalogLockList().get(1).setAction(1);
            ProdStockCallService.AuditProductActivityStock(activityStockBean);

            //平台预售活动扣除规格库存后活动商品暂时不同步到MongoDB，等待买手缴纳保证金
			YmtProductActivityStock productActivityStock = new YmtProductActivityStockWapper().selectByProductId(activityStockBean.getProductID()).get(0);
			Logger.verifyEquals(1,productActivityStock.getiAction(),"验证action为1");

			updateproductactivitystockactionBean.setUserId(activityStockBean.getUserID());
			updateproductactivitystockactionBean.setProductId(activityStockBean.getProductID());
			updateproductactivitystockactionBean.setActivityId(activityStockBean.getActivityID());
			updateproductactivitystockactionBean.setActivityType(activityStockBean.getActivityType());
			updateproductactivitystockactionBean.setProductActivityId(activityStockBean.getProductActivityId());
			updateproductactivitystockactionBean.setAction(0);
			updateproductactivitystockactionCall.setData(updateproductactivitystockactionBean);
			updateproductactivitystockactionCall.callService();

			//同步到mongo
			YmtProductActivityStock productActivityStock1 = new YmtProductActivityStockWapper().selectByProductId(activityStockBean.getProductID()).get(0);
			Logger.verifyEquals(0,productActivityStock1.getiAction(),"验证action为0");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_UpdateProductActivityStockAction_02() {
		Logger.start(true,"更新活动更新活动商品状态,预售活动");
		try {
			AuditProductActivityStockBean activityStockBean = ProdStockCallService.initAuditProductActivityStockBean(sellerId);
			activityStockBean.setActivityType(2);
			activityStockBean.getFBXCatalogLockList().get(0).setEarnest(10);
			activityStockBean.getFBXCatalogLockList().get(0).setEarnestDedution(15);
			activityStockBean.getFBXCatalogLockList().get(0).setAction(1);

			activityStockBean.getFBXCatalogLockList().get(1).setEarnest(20);
			activityStockBean.getFBXCatalogLockList().get(1).setEarnestDedution(10);
			activityStockBean.getFBXCatalogLockList().get(1).setAction(1);
			ProdStockCallService.AuditProductActivityStock(activityStockBean);

			ProdStockCallService.AuditProductActivityStock(activityStockBean);

			//平台预售活动扣除规格库存后活动商品暂时不同步到MongoDB，等待买手缴纳保证金
			YmtProductActivityStock productActivityStock = new YmtProductActivityStockWapper().selectByProductId(activityStockBean.getProductID()).get(0);
			Logger.verifyEquals(1,productActivityStock.getiAction(),"验证action为1");

			updateproductactivitystockactionBean.setUserId(activityStockBean.getUserID());
			updateproductactivitystockactionBean.setProductId(activityStockBean.getProductID());
			updateproductactivitystockactionBean.setActivityId(activityStockBean.getActivityID());
			updateproductactivitystockactionBean.setActivityType(activityStockBean.getActivityType());
			updateproductactivitystockactionBean.setProductActivityId(activityStockBean.getProductActivityId());
			updateproductactivitystockactionBean.setAction(0);
			updateproductactivitystockactionCall.setData(updateproductactivitystockactionBean);
			updateproductactivitystockactionCall.callService();

			//同步到mongo
			YmtProductActivityStock productActivityStock1 = new YmtProductActivityStockWapper().selectByProductId(activityStockBean.getProductID()).get(0);
			Logger.verifyEquals(0,productActivityStock1.getiAction(),"验证action为0");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}